package cn.tqfeiyang.smartadmin.office.constant;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

/**
 * 枚举基类j
 *
 * @author tqfeiyang
 * @since 2024/9/4 15:39
 */
public interface BaseEnum {

    /**
     * 获取枚举类的值
     *
     * @return int
     */
    Integer getValue();

    /**
     * 获取枚举类的说明
     *
     * @return String
     */
    String getDescription();

    /**
     * 获取数值对应的枚举值
     *
     * @param clazz
     * @param value
     * @return 枚举值
     */
    static <T extends BaseEnum> T getEnum(Class<T> clazz, int value) {
        T[] constants = clazz.getEnumConstants();

        for (T t : constants) {
            if (t.getValue() == value) {
                return t;
            }
        }
        return null;
    }

}
